<script>
import outMain from "@/components/outMain.vue";
import { ElMessage, ElMessageBox } from "element-plus";
import { Cooperate_enterprise, Cooperate_enterpriseDel } from "@/http/api";
export default {
  components: { outMain },
  name: "",
  data() {
    return {
      tableData: [],
      queryData: {
        c_enterprise_name: "",
        page: 1,
        per_page: 20,
      },
      total: 0,
    };
  },
  props: {},
  setup() {},
  methods: {
    deleteFn(row) {
      ElMessageBox.confirm("确定删除选择的合作企业吗?", "删除提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(async () => {
        const { data } = await Cooperate_enterpriseDel({
          c_enterprise_id: row.c_enterprise_id,
        });
        if (data.code == 1) {
          ElMessage({
            type: "success",
            message: "删除成功",
          });
          this.getData();
        }
      });
    },
    addFn(id) {
      this.$router.push({
        path: "/cooperationBooterAdd",
        query: { id: id, page: id ? this.queryData.page : undefined },
      });
    },
    detailFn(id) {
      this.$router.push({
        path: "/cooperationBooterDetail",
        query: { id: id, page: this.queryData.page },
      });
    },
    async getData() {
      const { data } = await Cooperate_enterprise(this.queryData);
      if (data.code == 1) {
        this.tableData = data.data.data;
        this.total = data.data.total;
      }
    },
  },
  mounted() {},
  created() {
    this.queryData.page = Number(localStorage.getItem("boot_page")) || 1;

    this.getData();
  },
};
</script>
<template>
  <outMain>
    <div class="tableCont">
      <div class="tableName flexCont">
        <div>合作管理（{{ total }}）</div>
      </div>
      <div class="tableSerch">
        <div class="serchLeft">
          <btn value="新增" @ok="addFn"></btn>
        </div>
        <div class="serchRight">
          <el-form class="flexCenter" :inline="true">
            <el-form-item>
              <el-input
                clearable
                @clear="getData"
                @keyup.enter="getData"
                v-model="queryData.c_enterprise_name"
                placeholder="请输入合作企业"
              />
            </el-form-item>
            <btn value="搜索" @ok="getData"></btn>
          </el-form>
        </div>
      </div>
      <el-table class="tableMain" :data="tableData" stripe style="width: 100%">
        <el-table-column
          prop="c_enterprise_name"
          show-overflow-tooltip
          width="180"
          label="合作名称"
        />
        <el-table-column
          prop="c_enterprise_city"
          width="150"
          show-overflow-tooltip
          label="所在城市"
        />
        <el-table-column
          prop="bind_c_num"
          show-overflow-tooltip
          label="绑定船舶"
        >
          <template #default="{ row }">{{ row.bind_c_num }}条</template>
        </el-table-column>
        <el-table-column prop="gw_num" show-overflow-tooltip label="岗位数量" />
        <el-table-column
          prop="qy_user_num"
          show-overflow-tooltip
          label="签约船员"
        />
        <el-table-column
          prop="staff"
          width="100"
          show-overflow-tooltip
          label="企业状态"
        >
          <template #default="{ row }">
            <div class="tagGroup">
              <el-tag v-if="row.c_enterprise_status === 1">待审核</el-tag>
              <el-tag type="success" v-if="row.c_enterprise_status === 2"
                >正常</el-tag
              >
              <el-tag type="danger" v-if="row.c_enterprise_status === 3"
                >已驳回</el-tag
              >
            </div>
          </template>
        </el-table-column>
        <el-table-column
          width="120"
          prop="wait_js_money"
          show-overflow-tooltip
          label="管理费结算"
        >
          <template #default="{ row }">
            <el-tag v-if="row.wait_js_count == 0">无需结算</el-tag>
            <el-tag type="danger" v-if="row.wait_js_count > 0"
              >待结算({{ row.wait_js_count }})</el-tag
            >
          </template>
        </el-table-column>
        <el-table-column prop="Name" width="140" label="操作">
          <template #default="{ row }">
            <div class="tableCtrl">
              <div
                class="greenText ctrlText"
                @click="detailFn(row.c_enterprise_id)"
              >
                详情
              </div>
              <div
                v-if="row.is_auth == 1"
                class="blueText ctrlText"
                @click="addFn(row.c_enterprise_id)"
              >
                编辑
              </div>
              <div
                class="redText ctrlText"
                v-if="row.is_auth == 1 && false"
                @click="deleteFn(row)"
              >
                删除
              </div>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="pageCont">
        <el-pagination
          v-model:currentPage="queryData.page"
          v-model:page-size="queryData.per_page"
          background
          layout="total, prev, pager, next, jumper"
          :total="total"
          @size-change="getData"
          @current-change="getData"
        />
      </div>
    </div>
  </outMain>
</template>
<style scoped lang="less"></style>
